#!/bin/bash
# 将成果物mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz和mysql_install.sh上传到/home/mysql下
tar xzvf /home/mysql/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
cp -rf /home/mysql/"mysql-5.7.31-linux-glibc2.12-x86_64" /usr/local/
mv /usr/local/"mysql-5.7.31-linux-glibc2.12-x86_64" /usr/local/mysql
mkdir /usr/local/mysql/data

# 创建mysql组
groupadd mysql
# 创建mysql用户添加到mysql组
useradd -g mysql mysql
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql

# 获取控制台上的密码
/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql


# 配置my.cnf
cat /dev/null > /etc/my.cnf
echo [mysqld] >> /etc/my.cnf
echo datadir=/usr/local/mysql/data >> /etc/my.cnf
echo port=3306 >> /etc/my.cnf
echo sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES >> /etc/my.cnf
echo symbolic-links=0 >> /etc/my.cnf
echo max_connections=600 >> /etc/my.cnf
echo innodb_file_per_table=1 >> /etc/my.cnf
echo lower_case_table_names=1 >> /etc/my.cnf
echo character_set_server=utf8 >> /etc/my.cnf

# 创建启动软连接
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
 